package cn.ld.module.system.dal.mapper.dict;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.dict.vo.type.DictTypePageInVO;
import cn.ld.module.system.dal.entity.dict.DictTypeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface DictTypeMapper extends BaseMapperX<DictTypeEntity> {

    default PageResult<DictTypeEntity> selectPage(DictTypePageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<DictTypeEntity>()
                .likeIfPresent(DictTypeEntity::getName, inVO.getName())
                .likeIfPresent(DictTypeEntity::getType, inVO.getType())
                .eqIfPresent(DictTypeEntity::getStatus, inVO.getStatus())
                .betweenIfPresent(DictTypeEntity::getCreateTime, inVO.getCreateTime())
                .orderByDesc(DictTypeEntity::getId));
    }

    default DictTypeEntity selectByType(String type) {
        return selectOne(DictTypeEntity::getType, type);
    }

    default DictTypeEntity selectByName(String name) {
        return selectOne(DictTypeEntity::getName, name);
    }

    @Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);

}
